home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_06_03
/
v6n3038a.txt
< prev
next >
Wrap
Text File
|
1989-09-26
|
3KB
|
77 lines
char *memmove(dest, src, cnt)
char *dest, *src;
unsigned cnt;
{
char *p;
p = dest;
while (cnt--)
*dest++ = *src++;
return (p);
}
SHR CX,1 ; convert bytes to words (divide CX by 2)
JZ MovByte ; jump if number of words is zero
REP MOVSW ; move a word at a time
MovByte: JNC Done ; jump if number of bytes is zero
MOVSB ; move the byte
Done:
/*
** movtst.c -- program to test the functions moveleft, moveright
** and memmove.
*/
char string[] = { "This is the text in this array" };
char string2[] = { "This is another, second array" };
main()
{
char *retval, *moveleft(), *moveright(), *memmove();
printf("string = -->%s<--\n", string);
retval = moveright(string, &string[9], 10);
printf("string = -->%s<--\n", string);
printf("retval = -->%s<--\n", retval);
retval = moveleft(&string[2], string, 10);
printf("string = -->%s<--\n", string);
printf("retval = -->%s<--\n", retval);
retval = moveleft(&string[1], &string[22], 8);
printf("string = -->%s<--\n", string);
printf("retval = -->%s<--\n", retval);
printf("\nstring2 = -->%s<--\n", string2);
retval = memmove(&string2[9], &string2[16], 13);
printf("string2 = -->%s<--\n", string2);
printf("retval = -->%s<--\n", retval);
retval = memmove(&string2[17], &string2[10], 12);
printf("string2 = -->%s<--\n", string2);
printf("retval = -->%s<--\n", retval);
}
Running this program should produce the following output:
string = -->This is the text in this array<--
string = -->ne text ine text in this array<--
retval = -->ne text ine text in this array<--
string = -->nenenenenenetext in this array<--
retval = -->nenenenenetext in this array<--
string = -->nis arrayenetext in this array<--
retval = -->is arrayenetext in this array<--
string2 = -->This is another, second array<--
string2 = -->This is a second arrayd array<--
retval = --> second arrayd array<--
string2 = -->This is a second second array<--
retval = -->second array<--